package com.java复习.集合的学习;

import java.util.ArrayList;
import java.util.List;

public class 泛型 {
    public static void main(String[] args) {

        //泛型，避免类型转换错误，可以约定集合只可以存放指定类型的数据
        List<Stu> stus = new ArrayList<Stu>();
        Stu stu1 = new Stu("小明",21);
        Stu stu2 = new Stu("小花",20);
        Stu stu3 = new Stu("小黑",22);
        stus.add(stu1);
        stus.add(stu2);
        stus.add(stu3);

        Stu stu = stus.get(2);

        System.out.println(stu);
    }
}

class Stu{
    public String name;
    public int age;

    public Stu(String name, int age) {
    }



    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Stu{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

}
